package refect;


import refect.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RefectDemo03Contructors {
    public static void main(String[] args)
            throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {

        // 0. 获取Class对象
        Class psersonClass = Person.class;

        // 1. 创建对象
//        Constructor[] constructor = psersonClass.getConstructors();
        Constructor constructor1 = psersonClass.getConstructor(String.class, int.class);

        Object person1 = constructor1.newInstance("张三", 123);
        System.out.println(person1);

        System.out.println("----------------");

        Object person2 = psersonClass.newInstance();
        System.out.println(person2);

        System.out.println("----------------");

        // 暴力反射
        constructor1.setAccessible(true);



    }

}
